<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
<meta charset="UTF-8">
<style>
#header {
    background-color:lightgray;
    color:black;
    text-align:left;
    padding:5px;
}
#nav {
    line-height:30px;
    background-color:#eeeeee;
    height:300px;
    width:100px;
    float:left;
    padding:5px;	      
}
#section {
    width:350px;
    float:left;
    padding:10px;	 	 
}
#footer {
    background-color:black;
    color:white;
    clear:both;
    text-align:center;
   padding:5px;	 	 
}
</style>
<title>数字示波器</title>
</head>
<body>
<div id="header">
<h1 style="margin-left: 400px;">维测</h1>
<a href="/index.html" style="margin-right: 50px;">数字示波器</a>
<a href="/generator.html" style="margin-right: 50px;">波形发生器</a>
<a href="/file.html" style="margin-right: 50px;">文件</a>
<a href="/log.html" style="margin-right: 50px;">维测</a>
<label id="Version">版本:</label>
</div>
<p/>
<input type="button" id="LogClear" value="清除维测" onclick="ClearAllLog()"/>
<label for="Voltage" style="margin-left: 30px;">调测命令：</label>
<input type="input" id="Command" name="Command" size="10" value="Cali=0" />
<input type="button" id="SendCommand" value="发送" onclick="SendCommand()"/>
<br/>
<textarea id="AllLogText" rows="30" cols="100" readonly="1" style="overflow-y:auto; overflow-x:auto;">
</textarea>
<script>
	function ClearAllLog() {
		document.getElementById("AllLogText").value = "";
	}

	function SendCommand() {
		SendHttpRequest("/setting.cgi" + "?" + document.getElementById("Command").value, 0);
	}

	function SendReadLogRequesetCb(responseText) {
		document.getElementById("AllLogText").value += responseText;
		SendReadLogRequeset();
	}

	function SendReadLogRequeset() {
		SendHttpRequest("/log.txt", SendReadLogRequesetCb);
	}

	function SendHttpRequest(url, callback) {
		var xhttp = new XMLHttpRequest();
		xhttp.onreadystatechange = function() {
			if (this.readyState == 4 && this.status == 200) {
				if (callback) {
					callback(this.responseText);
				}
				xhttp.abort();
			}
		};
		xhttp.open("GET", url, true);
		xhttp.send();
	}

	function SendVersionCb(responseText) {
		console.log("version: " + responseText);
		document.getElementById("Version").innerText = "版本: " + responseText;
	}

    window.onload = function() {
		SendHttpRequest("/version.txt", SendVersionCb);
		SendReadLogRequeset();
    }
</script>
</body>
</html>
